# Project: diff_ext
# Generates diff_ext_for_kdiff3.dll with gcc.
# Can be used for Cygwin and MingW (MingW ignores -mno-cygwin)
#
PROJ := diff_ext_for_kdiff3

CXX  ?= g++.exe

ifdef DEBUG
  CXXFLAGS ?= -g
else
  CXXFLAGS ?= -Os
  LDFLAGS += -L. -s -static-libgcc
endif
CXXFLAGS += -pedantic -Wall -W -D_UNICODE -DUNICODE

LIBS :=  -luuid -lole32
DEFFILE = $(PROJ).def
STATICLIB = $(PROJ).a
EXPLIB = $(PROJ).exp

SRC-CXX = $(wildcard *.cpp)
SRC-RC = $(wildcard *.rc)

OBJ  := $(SRC-CXX:.cpp=.o)
RES  := $(SRC-RC:.rc=.res)
OBJ += $(RES)
DLL  := $(PROJ).dll

.PHONY: all clean

.SUFFIXES: .rc .res

all: .depend $(DLL)

debug:
	$(MAKE) DEBUG=YES UNICODE=YES

release:
	$(MAKE) 

.depend: Makefile $(SRC-RC) $(SRC-CXX)
	$(CXX) -M $(CXXFLAGS) $(SRC-RC) $(SRC-CXX) > .depend
	
include .depend

clean:
	del  .depend $(OBJ) $(DLL) ${EXPLIB} $(STATICLIB)

$(DLL): $(OBJ)
	dllwrap.exe \
		--def $(DEFFILE) \
		--output-exp ${EXPLIB} \
		--driver-name c++ -L/usr/local/lib -L/usr/lib/mingw \
		--implib $(STATICLIB) \
		$(OBJ) $(LDFLAGS) $(LIBS) \
		-o $@

.cpp.o:
	$(CXX) $(CXXFLAGS) -c $< -o $@ 

.rc.res:
	windres.exe  $< -J rc -o $@ -O coff -DMING
